home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3.iso
/
chapte18
/
ex1.c
next >
Wrap
C/C++ Source or Header
|
1994-12-27
|
4KB
|
102 lines
#include <genstub.c>
LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hNextViewer ; /* Next viewer in the clipboard viewer chain */
switch (uMsg) /* process windows messages */
{
case WM_CREATE: /* make this application a clipboard viewer */
hNextViewer = SetClipboardViewer( hWnd );
SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)"My Clipboard Viewer");
break;
// right button mouse interface
#include <rbutton.c>
case WM_PAINT: {
PAINTSTRUCT ps; // paint params from BeginPaint
HBITMAP hBitmap; // handle to bitmap on clipboard
RECT rClientRect; // area to write in
HANDLE hMem; // handle to text on clipboard
BeginPaint( hWnd, &ps );
GetClientRect( hWnd, &rClientRect );
OpenClipboard( hWnd );
if (hMem = GetClipboardData( CF_TEXT ))
{
/* try to get data as CF_TEXT format first */
LPSTR lpMem = GlobalLock( hMem );
DrawText( ps.hdc, lpMem, -1, &rClientRect, DT_LEFT );
GlobalUnlock( hMem );
}
else if (hBitmap = GetClipboardData( CF_BITMAP ))
{ /* if there is no text, try CF_BITMAP format */
BITMAP bm;
HDC hMemDC = CreateCompatibleDC( ps.hdc );
SelectObject( hMemDC, hBitmap );
GetObject( hBitmap, sizeof (BITMAP), (LPSTR) &bm );
BitBlt( ps.hdc, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY );
DeleteDC( hMemDC );
}
CloseClipboard( );
EndPaint( hWnd, &ps );
}
break ;
case WM_DRAWCLIPBOARD:
if (hNextViewer)/* relay message to next viewer */
SendMessage( hNextViewer, WM_DRAWCLIPBOARD,wParam, lParam );
InvalidateRect( hWnd, NULL, TRUE ); /* Force repaint of own window*/
break;
case WM_CHANGECBCHAIN:
// Process this message to update hNextViewer static
// if the next clipboard viewer is going away.
if (wParam == hNextViewer)
hNextViewer = LOWORD(lParam);
else if (hNextViewer) /* relay message to next viewer */
SendMessage( hNextViewer, WM_CHANGECBCHAIN, wParam, lParam );
break;
case WM_COMMAND: /* process menu items */
switch (LOWORD(wParam)) {
case IDM_TEST:
/* empty the clipboard */
OpenClipboard( hWnd );
EmptyClipboard( );
CloseClipboard( );
/* Force repaint. */
InvalidateRect( hWnd, NULL, TRUE );
break ;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
#include <aboutopt.c>
}
break;
case WM_DESTROY: /* stop application */
if (hNextViewer && !ChangeClipboardChain( hWnd, hNextViewer ))
{
// Serious problem, most likely a bug in the detection of next chain change.
char szErrMsg[128];
wsprintf( szErrMsg, "Clipboard chain corrupt. Err %d detected. Next viewer: %x",
GetLastError(), hNextViewer );
MessageBox( hWnd, szErrMsg, "Fatal System Error", MB_OK );
}
PostQuitMessage( 0 );
break ;
default:
/* default windows message processing */
return DefWindowProc( hWnd, uMsg, wParam, lParam);
}
return (0L) ;
}
#include <about.c>